package com.prime.tutorial.moviestore.view.logistics;

import com.prime.tutorial.moviestore.domain.Device;
import com.prime.tutorial.moviestore.service.logistics.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.faces.event.ActionEvent;
import java.util.List;

@Component("deleteDevice")
@Scope("request")
public class DeleteDevice {
    private LogisticsService logisticsService;
    private Device deviceToDelete;
    private Device[] arrayDeviceToDelete;
    private List<Device> devicesToDelete;

    @Autowired
    public DeleteDevice(LogisticsService logisticsService) {
//        setLogisticsService(logisticsService);
//        setDevicesToDelete(logisticsService.getDevicesOnStorage());
      this.logisticsService=logisticsService;
      this.devicesToDelete=logisticsService.getDevicesOnStorage();
    }

    public void deleteDevice(ActionEvent e){
//        logisticsService.deleteDevice(deviceToDelete);
////        setDeviceToDelete(null);
//        deviceToDelete=null;
        for(int i=0;i< getArrayDeviceToDelete().length;i++){
            logisticsService.deleteDevice(getArrayDeviceToDelete()[i]);
        }
        setArrayDeviceToDelete(null);

    }
    
    public LogisticsService getLogisticsService() {
        return logisticsService;
    }

    public void setLogisticsService(LogisticsService logisticsService) {
        this.logisticsService = logisticsService;
    }

    public Device getDeviceToDelete() {
        return deviceToDelete;
    }

    public void setDeviceToDelete(Device deviceToDelete) {
        this.deviceToDelete = deviceToDelete;
    }
        public List<Device> getDevicesToDelete() {
        return devicesToDelete;
    }

    public void setDevicesToDelete(List<Device> devicesToDelete) {
        this.devicesToDelete = devicesToDelete;
    }

    public Device[] getArrayDeviceToDelete() {
        return arrayDeviceToDelete;
    }

    public void setArrayDeviceToDelete(Device[] arrayDeviceToDelete) {
        this.arrayDeviceToDelete = arrayDeviceToDelete;
    }
}
